const {
  get_teacher_info
} = require('../../Class/get_teacher_info.js');
const teacherInfo = new get_teacher_info();
Page({
  data: {
    active: 0,
    vant_tab: ['汉语言文学', '新闻学', '网络与新媒体'],
    flag: false,
    flag1: false
  },
  open() {
    this.setData({
      flag: !this.data.flag,
      flag1: true
    })
  },
  onChange(e) {
    if (e == null) {
      var id = 0
    } else {
      var id = parseInt(e.detail.index)
    }
    const user_result = teacherInfo.GetUserChoice(id, this.data.hanyuyan, this.data.xinwen, this.data.wangxin);
    this.setData({
      teacher: user_result,
      tabid: id
    })
  },

  UserChoice(e) {
    var tabid = this.data.tabid
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/teachers-team/introduce/introduce?tabid='+tabid + '&teacherid=' + id,
    })
  },

  userInput(e) {
    var user_content = e.detail.value
    const teacher_total_data = [...this.data.hanyuyan, ...this.data.xinwen, ...this.data.wangxin]
    var search_result = []
    if (user_content == '' || undefined || null) {
      wx.showToast({
        title: '请输入内容',
        icon: 'none'
      })
    } else {
      var flag = false
      for (let index = 0; index < teacher_total_data.length; index++) {
        if (teacher_total_data[index].name.includes(user_content)) {
          search_result.push(teacher_total_data[index])
          flag = true
        }
      }
      if (flag == true) {
        wx.showModal({
          title: '此功能暂未开放',
          showCancel:false
        })
        // wx.navigateTo({
        //   url: '/pages/teachers-team/search/search?search_result=' + JSON.stringify(search_result) + '&search=' +user_content,
        // })
      } else {
        wx.showModal({
          content: '抱歉！未找到你想搜索的老师',
          showCancel: false
        })
      }
    }
  },

  async onLoad(options) {
    wx.showLoading({
      title: '数据通信中',
      mask: true
    })
    try {
      const result = await teacherInfo.GetTeacherInfo();
      const hanyuyan = result.hanyuyan
      const xinwen = result.xinwen
      const wangxin = result.wangxin
      this.setData({
        hanyuyan,
        xinwen,
        wangxin
      })
    } catch (err) {
      console.log(err)
    }
    wx.hideLoading()
    this.onChange(null)
  },
})